extends Area2D

var direction = Vector2.RIGHT
var speed = 200.0
var damage = 12
var slow_factor = 0.6
var slow_duration = 2.0
var max_range = 300.0
var distance_traveled = 0.0
var source = null

func _ready():
	# 设置碰撞检测
	connect("body_entered", _on_body_entered)
	
	# 设置初始旋转
	rotation = direction.angle()

func _process(delta):
	# 移动绷带投射物
	var movement = direction * speed * delta
	position += movement
	
	# 飘动效果
	rotation = direction.angle() + sin(Time.get_ticks_msec() * 0.01) * 0.2
	
	# 计算已移动距离
	distance_traveled += movement.length()
	
	# 超出最大范围后消失
	if distance_traveled >= max_range:
		queue_free()

func _on_body_entered(body):
	# 检查是否击中玩家
	if body.is_in_group("player") and body.has_method("take_damage"):
		# 造成伤害
		body.take_damage(damage)
		
		# 应用减速效果
		if body.has_method("apply_slow_effect"):
			body.apply_slow_effect(slow_factor, slow_duration)
		
		# 创建缠绕效果
		var wrap_effect = preload("res://BandageWrapEffect.tscn").instantiate()
		get_tree().get_root().add_child(wrap_effect)
		wrap_effect.global_position = global_position
		
		# 销毁投射物
		queue_free()
	
	# 检查是否击中墙壁等障碍物
	elif not body.is_in_group("enemies"):
		# 创建击中效果
		var hit_effect = preload("res://HitEffect.tscn").instantiate()
		get_tree().get_root().add_child(hit_effect)
		hit_effect.global_position = global_position
		
		# 销毁投射物
		queue_free()
